package com.yourcompany.web.controller;

import cn.dev33.satoken.util.SaResult;
import com.yourcompany.api.dto.CreditPayDTO;
import com.yourcompany.api.dto.OrderCreateDTO;
import com.yourcompany.api.dto.OrderPayDTO;
import com.yourcompany.api.entity.Order;
import com.yourcompany.api.service.OrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "订单管理")
@RestController
@RequestMapping("/order")
public class OrderController {
    
    @Autowired
    private OrderService orderService;
    
    @Operation(summary = "使用先充后付支付订单")
    @PostMapping("/pay/credit")
    public SaResult payWithCredit(@RequestBody CreditPayDTO creditPayDTO) {
        String result = orderService.payOrderWithCredit(creditPayDTO);
        return SaResult.data(result);
    }
    
    @Operation(summary = "创建订单")
    @PostMapping("/create")
    public SaResult createOrder(@RequestBody OrderCreateDTO createDTO) {
        Order order = orderService.createOrder(createDTO);
        return SaResult.data(order);
    }
    
    @Operation(summary = "取消订单")
    @PostMapping("/cancel/{orderId}")
    public SaResult cancelOrder(@PathVariable Long orderId) {
        orderService.cancelOrder(orderId);
        return SaResult.ok();
    }
    
    @Operation(summary = "支付订单")
    @PostMapping("/pay")
    public SaResult payOrder(@RequestBody OrderPayDTO payDTO) {
        String result = orderService.payOrder(payDTO);
        return SaResult.data(result);
    }
} 